package com.easychat.mychat.userservice.Controller;

import com.easychat.mychat.common.Controller.ABaseController;

import com.easychat.mychat.common.annotation.GlobalInteceptor;
import com.easychat.mychat.common.entity.enums.ResponseCodeEnum;
import com.easychat.mychat.common.entity.po.GroupInfo;
import com.easychat.mychat.common.entity.query.GroupInfoQuery;
import com.easychat.mychat.common.entity.vo.PaginationResultVO;
import com.easychat.mychat.common.entity.vo.ResponseVO;
import com.easychat.mychat.common.exception.BusinessException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;

/**
 * @Description
 * @Author susu
 * @Date 2024/9/8
 */
@RestController
@RequestMapping("/admin")
public class AdminGroupController extends ABaseController {

    @Resource
    private GroupInfoService groupInfoService;

    @RequestMapping("/loadGroup")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO loadGroup(GroupInfoQuery query){
        query.setOrderBy("create_time desc");
        query.setQueryGroupOwnerName(true);
        query.setQueryMemberCount(true);
        PaginationResultVO<GroupInfo> listByPage = groupInfoService.findListByPage(query);
        return getSuccessResponseVO(listByPage);
    }

    @RequestMapping("/dissolutionGroup")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO dissolutionGroup(@NotEmpty String groupId){
        GroupInfo info = groupInfoService.getGroupInfoByGroupId(groupId);
        if (info == null){
            throw new BusinessException(ResponseCodeEnum.CODE_600);
        }
        groupInfoService.dissolutionGroup(info.getGroupOwnerId(),groupId);

        return getSuccessResponseVO(null);
    }
//
//    @RequestMapping("/delBeautAccount")
//    @GlobalInteceptor(checkAdmin = true)
//    public ResponseVO delBeautAccount(Integer id){
//
//        return getSuccessResponseVO(null);
//    }
}
